﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EntityModel;
using GUI;
using System.Security.Cryptography;
using GUIServerConnectorAPI;

namespace GUI
{
    public partial class AddUserForm : Form
    {
        private AdminForm adminForm;
        private Guid sessionId;

        public AddUserForm(AdminForm adminForm)
        {
            InitializeComponent();
            this.adminForm = adminForm;
        }

        public void Show(Guid sessionId)
        {
            this.sessionId = sessionId;
            Show();
        }

        private void AddNewRecord()
        {

              //Date User
            /*
            User pacientUser = new User();
            pacientUser.idUser = new Guid();
            pacientUser.Username = UsernametextBox.Text;
            MD5CryptoServiceProvider md5CryptoServiceProvider = new MD5CryptoServiceProvider();
            pacientUser.Password = md5CryptoServiceProvider.ComputeHash(System.Text.Encoding.ASCII.GetBytes(PasswordtextBox.Text));
            pacientUser.Rol = RoltextBox.Text;
            //Date Pacient
            Pacient pacient = new Pacient();
            pacient.User = pacientUser;
            pacient.Nume = NumetextBox.Text;
            pacient.Prenume = PrenumetextBox.Text;
            pacient.Sex = SextextBox.Text;
            pacient.Telefon = TelefontextBox.Text;
            pacient.Adresa = AdresatextBox.Text;
            pacient.CNP = CNPtextBox.Text;
            pacient.Data_nasterii = DataNasteriidtPicker.Value;
            pacient.Email = EmailtextBox.Text;
            pacient.Istoric_medical = IstoricMedicalrichTextBox.Text;
            pacient.Lista_alergi = ListaAlergiirichTextBox.Text;
            */
        //    GUIServerConnector.getInstance().getServerInterface().addPacientData(sessionId, pacient);
            //USING ENTITY FRAMEWORK
        /*    using (var context = new TeleasistentaEntities())
            {
                try
                {
                    User userPacient = new User();
                    userPacient.idUser = Guid.NewGuid();
                    userPacient.Rol = textBox3.Text;
                    userPacient.UserName = textBox1.Text;
                    userPacient.UserPassword = textBox2.Text;

                    context.Users.AddObject(userPacient);
                    // Hard code data for a new record, for testing.
                    context.Pacients.AddObject(new Pacient()
                    {
                        idPacient = userPacient.idUser,
                        Adresa = textBox4.Text,
                        CNP = textBox5.Text,
                        DataNasterii = DateTime.Now,
                        Email = textBox7.Text,
                        IstoricMedical = richTextBox1.Text,
                        ListaAlergi = richTextBox2.Text,
                        Nume = textBox8.Text,
                        Prenume = textBox9.Text,
                        Sex = textBox10.Text,
                        Telefon = textBox11.Text,


                    });
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }*/
           // }
        }

        private void AddPacientForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Hide();
            adminForm.Show();
        }

        private void AddPacientForm_Load(object sender, EventArgs e)
        {

        }
    }
}
